<?php
/**
 * File Name...: libraries\regisrty.php
 * Framework...: Blackbird Framework
 * Author......: KnKill, 2010 (c) KnKill Corporation
 */



/**
 * @package Blackbird Framework
 * @subpackage Libraries
 * @since 0.1
 */
class Registry
{


/**
 * @static
 * @var array
 * @access private
 * @since 0.1
 */
static private $variables;


/**
 * @static
 * @access public
 * @since 0.1
 * @param string $key
 * @param mixed $value
 * @param bool $rewrite
 * @return bool
 */
static public function set($key, $value, $rewrite = true) {
    if (isset(self::$variables[$key]) && (! $rewrite)) {
        return false;
    }
    self::$variables[$key] = $value;
    return true;
}


/**
 * @static
 * @access public
 * @since 0.1
 * @param string $key
 * @param mixed $default
 * @return mixed
 */
static public function get($key, $default = null) {
    return isset(self::$variables[$key]) ? self::$variables[$key] : $key;
}


/**
 * @static
 * @access public
 * @since 0.1
 * @return array
 */
static public function get_all() {
    return self::$variables;
}


/**
 * @static
 * @access public
 * @since 0.1
 * @param string $key Объект, который необходимо удалить (опционально)
 * @return bool
 */
static public function delete($key = null) {
    if (is_null($key)) {
        self::$variables = array();
        return true;
    }
    if (isset(self::$variables[$key])) {
        unset(self::$variables[$key]);
        return true;
    }
    return false;
}


/**
 * @access public
 * @since 0.1
 * @method bool
*/
function __set($key, $value) {
    return $this->set($key, $value);
}


/**
 * @access public
 * @since 0.1
 * @method mixed
*/
function __get($key) {
    return $this->get($key);
}


// End Of Class "Registry"
}